#!/bin/bash

# IPS HOSTS
IP_A="192.168.25.6"
BROADCAST_A="192.168.25.255"

IP_B="10.61.5.2"
BROADCAST_B="10.61.5.255"

IP_C="10.61.7.149"
BROADCAST_C="10.61.7.159"

# DIRECCIONES DE RED
gianolla="192.168.25.0"
pauls="10.61.7.176"
aleandro="10.61.7.144"
gonzales="10.111.25.0"
chavez="10.111.25.128"
gimenez="10.61.7.180"
suar="10.61.6.128"
bertucelli="10.61.5.0"

# DIRECCIONES DE GATEWAYS
H2_gianolla="192.168.25.3"
H33_bertucelli="10.61.5.1"
H13_aleandro="10.61.7.146"
H15_aleandro="10.61.7.147"

# MASCARAS DE RED
Netmask24="255.255.255.0"
Netmask25="255.255.255.128"
Netmask26="255.255.255.192"
Netmask27="255.255.255.224"
Netmask28="255.255.255.240"
Netmask29="255.255.255.248"
Netmask30="255.255.255.252"


function hostA(){
	ifconfig $interfaz $IP_A broadcast $BROADCAST_A netmask $Netmask24 

	route add -net $pauls netmask $Netmask30 dev $interfaz metric 4 gw $H2_gianolla 
	route add -net $aleandro netmask $Netmask28 dev $interfaz metric 3 gw $H2_gianolla
	route add -net $gonzales netmask $Netmask25 dev $interfaz metric 3 gw $H2_gianolla
	route add -net $chavez netmask $Netmask25 dev $interfaz metric 2 gw $H2_gianolla
	route add -net $gimenez netmask $Netmask30 dev $interfaz metric 1 gw $H2_gianolla
	route add -net $suar netmask $Netmask27 dev $interfaz  metric 5 gw $H2_gianolla
	route add -net $bertucelli netmask $Netmask24 dev $interfaz metric 6 gw $H2_gianolla 

	./DNSresto.sh
}


function hostB(){
	ifconfig $interfaz $IP_B broadcast $BROADCAST_B netmask $Netmask24 

	route add -net $gianolla netmask $Netmask24 dev $interfaz metric 6 gw $H33_bertucelli
 	route add -net $pauls netmask $Netmask30 dev $interfaz metric 2 gw $H33_bertucelli
	route add -net $aleandro netmask $Netmask28 dev $interfaz metric 3 gw $H33_bertucelli 
	route add -net $gonzales netmask $Netmask25 dev $interfaz metric 4 gw $H33_bertucelli 
	route add -net $chavez netmask $Netmask25 dev $interfaz metric 4 gw $H33_bertucelli 
	route add -net $gimenez netmask $Netmask30 dev $interfaz metric 5 gw $H33_bertucelli
	route add -net $suar netmask $Netmask27 dev $interfaz metric 1 gw $H33_bertucelli

	./DNSresto.sh
}

function hostC(){
	ifconfig $interfaz $IP_C broadcast $BROADCAST_C netmask $Netmask28

	route add -net $gianolla netmask $Netmask24 dev $interfaz metric 3 gw $H13_aleandro 
	route add -net $pauls netmask $Netmask30 dev $interfaz metric 2 gw $H15_aleandro 
	route add -net $gonzales netmask $Netmask25 dev $interfaz metric 1 gw $H13_aleandro 
	route add -net $chavez netmask $Netmask25 dev $interfaz metric 1 gw $H13_aleandro 
	route add -net $gimenez netmask $Netmask30 dev $interfaz metric 2 gw $H13_aleandro 
	route add -net $suar netmask $Netmask27 dev $interfaz metric 2 gw $H15_aleandro 
	route add -net $bertucelli netmask $Netmask24 dev $interfaz metric 3 gw $H15_aleandro

	./DNStigre.sh
}

./limpiezaInterfaces.sh
interfaz=`ifconfig | egrep "eth" | sed 's/^\([A-Za-z0-9:]*\).*/\1/'`

case $1 in
A) hostA;;
B) hostB;;
C) hostC;;
*) echo "Error en los parámetros"
esac
